<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/**
 * @package		Sunny CMS
 * @author		sonny@yuranga.com
 * @since		Version 1.0
 * @date: 20130621
 * @lastupdate: 20130621
 */

if (!function_exists('ci')) {
    /**
    * @return CI_Controller
    */
    function ci() {
        static $CI;
        if ( ! $CI) $CI = get_instance();
        return $CI;
    }

}

if (!function_exists('get')) {

    function get($key) {
//       $CI =& get_instance();
//       return $CI->$key;
        return ci()->$key;
    }

}

if (!function_exists('debug')) {

    function debug($data) {
      echo '<pre>' . print_r($data, true) . '</pre>';
    }
    
}
if (!function_exists('debug_log')) {

    function debug_log($data, $file = 'debug') {
        file_put_contents(APPPATH . '/logs/' . $file . '.log', print_r($data, true), FILE_APPEND);
    }
    
}

if (!function_exists('db_insert')) {

    function db_insert($table, $data) {
      get('db')->insert($table, $data);
    }
    
}
if (!function_exists('db_update')) {

    function db_update($table, $data, $cond) {
      get('db')->where($cond)->update($table, $data);
    }
    
}
/* config helper */
if (!function_exists('get_config')) {

    function get_config($config) {
      return ci()->config->item($config);
      //ci()->config->item('item name');
      //ci()->config->set_item('item_name', 'item_value');
     // Stored in an array with this prototype: ci()->config['blog_settings'] = $config
    // ci()->config->load('blog_settings', TRUE);
    // The third parameter allows you to suppress errors in the event that a config file does not exist:
      //ci()->config->load('blog_settings', FALSE, TRUE);
      
        // Loads a config file named blog_settings.php and assigns it to an index named "blog_settings"
        ci()->config->load('blog_settings', TRUE);
        get('config')->load('blog_settings', TRUE);
        // Retrieve a config item named site_name contained within the blog_settings array
        $site_name = ci()->config->item('site_name', 'blog_settings');
        get('config')->item('site_name', 'blog_settings');
        // An alternate way to specify the same item:
        $blog_config = ci()->config->item('blog_settings');
        $site_name = $blog_config['site_name'];
        get('config')->load('blog_settings');
        get('config')->item('site_name');

    }
    
}


//http://philsturgeon.co.uk/blog/2010/02/CodeIgniter-Base-Classes-Keeping-it-DRY
//http://www.gregaker.net/2011/mar/18/extending-codeigniters-controller/
//http://blog.daanraman.com/coding/extending-a-controller-using-my_controller-in-codeigniter-2-0-and-above/

// autocomplete config for netbeans when retrive ci via get_instance (singleton)
// https://github.com/elemental-shift/ExpressionEngine-Autocomplete
/**
* @var CI_Controller
*/
//protected $CI;

//singleton in line
/* @var $instance Singleton */
// $instance = Singleton::getInstance();
// second method
/**
 * @return Singleton
 */
//public static function getInstance() {
//
//}

//http://blog.bobbyallen.me/wp-content/uploads/2012/08/netbeans_autocomplete_codeigniter.txt
/* End of file ci_helper.php */
/* Location: ./application/helpers/ci_helper.php */